from PIL import Image,ImageDraw,ImageFont,ImageFilter
import random

#随机字母
def rand_char():
    return chr(random.randint(65,90))

#随机颜色
def rand_color():
    return (random.randint(64,255),random.randint(64,255),random.randint(64,255))


def rand_color2():
    return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))


def generate_image():
    image = Image.new('RGB',(240,60),(255,255,255))
    font = ImageFont.truetype('unifont.ttf',36)
    draw = ImageDraw.Draw(image)
    for x in range(240):
        for y in range(60):
            draw.point((x,y),fill=rand_color())

    code = ''
    for t in range(4):
        ch = rand_char()
        draw.text((60*t+10,10),ch,font=font,fill=rand_color2())
        code +=ch
    return (code,image)
